package com.voole.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.mapping.StatementType;
import org.springframework.stereotype.Repository;

import com.voole.entity.SysAuthority;

@Repository
public interface SysAuthorityDao {

	@Select(value="SELECT * FROM sys_authority ORDER BY sort")
	List<SysAuthority> getList();
	
	@Select(value="SELECT DISTINCT(sa.id) FROM sys_catalog sc LEFT JOIN sys_authority sa ON sc.authorityid=sa.id WHERE sc.id IN (${catalogIds})")
	List<Integer> getColumnAuthorityIdByCatalogId(@Param(value="catalogIds")String catalogIds);
	
	@Select(value="SELECT * FROM sys_authority WHERE id = ${param}")
	SysAuthority getSysAuthority(@Param(value="param")Integer authorityId);
	
	@Insert("INSERT INTO sys_authority (`authorityname`, `sort`, `status`) VALUES(#{authorityname}, #{sort}, #{status})")  
	@Options(useGeneratedKeys = true, keyProperty = "id")
	Integer addSysAuthority(SysAuthority sysAuthority);
	
	@Update("UPDATE sys_authority SET authorityname = #{authorityname}, sort = #{sort}, status = #{status} WHERE id = #{id} ")  
	Integer updateSysAuthority(SysAuthority sysAuthority);
	
	@Delete(value="delete from sys_authority where id = #{authorityId}")
	Integer delSysAuthority(Integer authorityId);
}